<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<html:header title="新增支出">
    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">
    <style type="text/css">
        .layui-form-item .layui-word-aux{
            font-size: 12px;
            color: #FF5722;
        }

        a{
            color: #01AAED;
            text-decoration: none;
            font-size: 12px;
        }
        a:hover {
            color: #FF5722;
        }
    </style>
    <script>
        jQuery(function () {
            $("[name='amt']").blur(function () {
                let amt = $(this).val();
                if (amt != ""){
                    amt = getPrice(amt);
                    $(this).val(amt);
                }
            });

            getByType("${baseUrl}",ORDER_TYPE.SZG.type, $("[name='no']"));
            $(".reloadNo").click(function () {
                getByType("${baseUrl}",ORDER_TYPE.SZG.type, $("[name='no']"),true);
            });

            ajaxSelect("${baseUrl}organization/store/getStores.action", "storeId");
            ajaxSelect("${baseUrl}budget/budgetProject/getAllOut.action", "budgetProjectId");
            ajaxSelect("${baseUrl}user/user/getAll.action", "userId");
            ajaxSelect("${baseUrl}settAccount/settAccount/listVo.action", "settAccountId");

            $("#close").click(function () {
                closeSubIframe();
            });

            layui.use(['form', 'layedit', 'laydate','element'], function(){
                var form = layui.form
                    ,layer = layui.layer
                    ,layedit = layui.layedit
                    ,laydate = layui.laydate;


                //日期
                laydate.render({
                    elem: '#date'
                });

                form.verify({
                    storeId: function(value, item){ //value：表单的值、item：表单的DOM对象
                        if(value == null || value==""){
                            return '门店不能为空';
                        }
                    },
                    settAccountId: function(value, item){ //value：表单的值、item：表单的DOM对象
                        if(value == null || value==""){
                            return '收入账户不能为空';
                        }
                    },
                    budgetProjectId: function(value, item){ //value：表单的值、item：表单的DOM对象
                        if(value == null || value==""){
                            return '账目类型不能为空';
                        }
                    },
                    amt: function(value, item){ //value：表单的值、item：表单的DOM对象
                        if(value == null || value==""){
                            return '应收金额不能为空';
                        }
                    },
                    userId: function(value, item){ //value：表单的值、item：表单的DOM对象
                        if(value == null || value==""){
                            return '经办人不能为空';
                        }
                    },

                });

                form.on('select(unitType)', function(data){
                    if (data.value == "1") {
                        $("#unitDiv").css("display","none");
                    } else if (data.value == "2") {
                        $("#unitDiv").css("display","block");
                        ajaxSelect("${baseUrl}custom/custom/getAll.action", "unit");
                    } else {
                        $("#unitDiv").css("display","block");
                        ajaxSelect("${baseUrl}provider/provider/getAll.action", "unit");
                    }
                });

                //监听提交
                form.on('submit(save)', function(data){
                    if (data.field.unit == "") {
                        data.field.unit = "1";
                    }

                    data.field.image = getImageNames();
                    data.field.date = genDate(data.field.date);

                    console.log(JSON.stringify(data.field));
                    tipLoad("新增中,请稍后...");
                    post("${baseUrl}budget/budget/add.action",data.field,function (resp) {
                        closeAll();
                        if (resp.code == 1){
                            refreshBudgetOut();
                            closeSubIframe();
                        } else {
                            errTip(resp.msg);
                        }
                    });
                    return false;
                });
            });
        });
    </script>
</html:header>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form" method="post" action="" lay-filter="form">
            <div>
                <button class="layui-btn" lay-submit="" lay-filter="save">保存</button>
                <a id="close" class="layui-btn layui-btn-primary" href="javascript:;">取消</a>
            </div>

            <hr>

            <input type="hidden" name="type" value="2">
            <div class="layui-form-item">
                <label class="layui-form-label">编号</label>
                <div class="layui-input-inline">
                    <input type="text" name="no" readonly="readonly" autocomplete="off"  class="layui-input readonly">
                </div>
                <div class="layui-input-inline" style="padding-top: 10px">
                    <a href="javascript:;" class="reloadNo">重新加载</a>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">业务日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="date" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">门店</label>
                <div class="layui-input-inline">
                    <select name="storeId" lay-search="" lay-verify="storeId">
                    </select>
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">收款单位</label>
                <div class="layui-input-inline">
                    <select name="unitType" lay-filter="unitType" lay-verify="unitType">
                        <option value="1">无</option>
                        <option value="2">客户</option>
                        <option value="3">供应商</option>
                    </select>
                </div>
                <div class="layui-input-inline" id="unitDiv" style="display: none;">
                    <select name="unit" lay-search="" lay-verify="unit">
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">账目类型</label>
                <div class="layui-input-inline">
                    <select name="budgetProjectId" lay-verify="budgetProjectId">
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">支出账户</label>
                <div class="layui-input-inline">
                    <select name="settAccountId" lay-verify="settAccountId" lay-verify="settAccountId"></select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">金额</label>
                <div class="layui-input-inline">
                    <input type="number" name="amt" autocomplete="off" class="layui-input" lay-verify="amt">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">经办人</label>
                <div class="layui-input-inline">
                    <select name="userId" lay-verify="userId">
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea class="layui-textarea" name="remark"></textarea>
                </div>
            </div>
        </form>

            <div class="layui-form-item">
                <label class="layui-form-label">图片附件</label>
                <html:imageAnnex type="budget" update="false"
                                 uploadUrl="${baseUrl}budget/budget/uploadImg.action"
                                 updateUrl="${baseUrl}budget/budget/updateImage.action"/>
            </div>
    </div>
</div>
</body>
<html:loading/>
</html>